<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <canvas id="c" width="600" height="400" style="border: 1px solid #ccc"></canvas>

        <script>
           const cnv = document.getElementById('c')
            const ctx = cnv.getContext('2d')

            var heartPath = new Path2D()
            heartPath.moveTo(300, 200)
            heartPath.bezierCurveTo(350, 150, 400, 200, 300, 250)
            heartPath.bezierCurveTo(200, 200, 250, 150, 300, 200)

            // ctx.stroke(heartPath)
            // ctx.fill(heartPath)

            var chartPath = new Path2D()
            chartPath.moveTo(200, 300)
            chartPath.quadraticCurveTo(150, 300, 150, 200)
            chartPath.quadraticCurveTo(150, 100, 300, 100)
            chartPath.quadraticCurveTo(450, 100, 450, 200)
            chartPath.quadraticCurveTo(450, 300, 250, 300)
            chartPath.quadraticCurveTo(250, 350, 150, 350)
            chartPath.quadraticCurveTo(250, 350, 200, 300)
            chartPath.closePath()

            // ctx.stroke(chartPath);
            ctx.clip(chartPath); // 裁剪
            ctx.rect(0,0,600,400)
            ctx.fill();
            ctx.lineWidth = 20
            ctx.strokeStyle = 'pink'
            ctx.stroke(chartPath);
        </script>

    </body>
</html>
